<?php
namespace Home\Controller;
use Think\Controller;
use Think\Page;
/**
* ==============================================
*  http://www.liuhuanhui.cn
* ==============================================
* @date: 2014-10-8
* @author:liuhuanhui
* @encoding: UTF-8
*/
class SortController extends  Controller
{
	/**
	 * 分类首页
	 */
	function index()
	{	
		if(I('key'))
		{
			$where['title']=array('like','%'.I('key').'%');
		}else
		if($_GET['sid']!=""){
			$where['sort_id']=I('sid');//根据id
		}
		$where['state']=array('neq','remove');//根据id
		$this->view($where);
		
	}
	/**
	 * 显示
	 */
	function view($where=null)
	{
    	$this->controls=D('PageControl')->where('page="List" and pid=0 and visible<>"n"')->order('number')->select();
    	$MB=D('BlogsView');
    	$MB->where($where);
		$page=new Page(M('blogs')->where($where)->count(),7);
		$page->baseUrl='page';
		$this->blogs=$MB->order('date desc')->limit($page->firstRow,$page->listRows)->select();
	
		$page->setConfig('theme', '%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
		$page->setConfig('next','&#xe628;');
		$page->setConfig('prev','&#xe629;');
		$this->show=$page->show();
		$this->display('index');
	}
	function date()
	{
		$date=explode('-',I('d'));
		$where="FROM_UNIXTIME(date,'%Y')=".$date[0]." and FROM_UNIXTIME(date,'%m')=".$date[1].' and state!="remove"';
		$this->view($where);
	}
	
}